home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / ftn / varargs.z / varargs
Encoding:
Text File  |  1998-10-30  |  7.4 KB  |  199 lines

  1.  
  2.  
  3.  
  4. VVVVAAAARRRRAAAARRRRGGGGSSSS((((3333FFFF))))                                                        VVVVAAAARRRRAAAARRRRGGGGSSSS((((3333FFFF))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      varargs, argmnt, getadr, nullok, xetarg, retour - allow variable number
  10.      of arguments in argument list
  11.  
  12. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  13.      ssssuuuubbbbrrrroooouuuuttttiiiinnnneeee aaaarrrrggggmmmmnnnntttt(((( nnnnaaaarrrrggggssss ))))
  14.      iiiinnnntttteeeeggggeeeerrrr****4444 nnnnaaaarrrrggggssss
  15.  
  16.      ssssuuuubbbbrrrroooouuuuttttiiiinnnneeee ggggeeeettttaaaaddddrrrr(((( nnnn,,,, iiiiaaaaddddddddrrrr ))))
  17.      iiiinnnntttteeeeggggeeeerrrr****4444 nnnn,,,, iiiiaaaaddddddddrrrr
  18.  
  19.      iiiinnnntttteeeeggggeeeerrrr****4444 ffffuuuunnnnccccttttiiiioooonnnn nnnnuuuullllllllooookkkk(((( nnnn,,,, iiiiaaaaddddddddrrrr ))))
  20.      iiiinnnntttteeeeggggeeeerrrr****4444 nnnn,,,, iiiiaaaaddddddddrrrr
  21.  
  22.      ssssuuuubbbbrrrroooouuuuttttiiiinnnneeee xxxxeeeettttaaaarrrrgggg(((( nnnn,,,, lllleeeennnn,,,, iiiiaaaarrrrgggg ))))
  23.      iiiinnnntttteeeeggggeeeerrrr****4444 nnnn,,,, lllleeeennnn
  24.      aaaannnnyyyyttttyyyyppppeeee iiiiaaaarrrrgggg
  25.  
  26.      ssssuuuubbbbrrrroooouuuuttttiiiinnnneeee rrrreeeettttoooouuuurrrr(((( nnnnaaaarrrrggggssss,,,, lllleeeennnn1111,,,, vvvvaaaallll1111,,,, lllleeeennnn2222,,,, vvvvaaaallll2222,,,, ............,,,, lllleeeennnnnnnn,,,, vvvvaaaallllnnnn ))))
  27.      iiiinnnntttteeeeggggeeeerrrr****4444 nnnnaaaarrrrggggssss,,,, lllleeeennnn1111,,,, lllleeeennnn2222,,,, ............,,,, lllleeeennnnnnnn
  28.      aaaannnnyyyyttttyyyyppppeeee vvvvaaaallll1111,,,, vvvvaaaallll2222,,,, ............,,,, vvvvaaaallllnnnn
  29.  
  30. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  31.      These utilities are used to provide f77 support for subroutines with
  32.      variable number of arguments.  In order to use these utilities, all
  33.      variable argument subroutines must be declared in each source file before
  34.      they are referenced or defined.   This is done by adding a $_v_a_r_a_r_g_s
  35.      compiler directive at the beginning of the source file.
  36.  
  37.      For example:
  38.  
  39.      $_v_a_r_a_r_g_s _v_a_s_u_b_1 _v_a_s_u_b_2 _v_a_s_u_b_3
  40.  
  41.      where _v_a_s_u_b_1, _v_a_s_u_b_2, and _v_a_s_u_b_3 are the names of the variable argument
  42.      subroutines which are referenced or defined in the current source file.
  43.  
  44.      _a_r_g_m_n_t returns the number of actual arguments in the integer variable
  45.      _n_a_r_g_s.  The default behavior is to count each character argument in the
  46.      actual argument list as two arguments since both the character address
  47.      and its length will be put on the argument stack.  The -_c_h_a_r_a_r_g_1 option
  48.      can be used to count each character argument as only one argument.
  49.  
  50.      _g_e_t_a_d_r returns the address of the _nth argument in the variable _i_a_d_d_r.
  51.      This function has to be used to get the length of a character argument
  52.      since it is passed by value, not by reference like other Fortran
  53.      arguments.
  54.  
  55.      _n_u_l_l_o_k returns 0 if the address of the _nth argument is the same as the
  56.      address contained in the variable _i_a_d_d_r.
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. VVVVAAAARRRRAAAARRRRGGGGSSSS((((3333FFFF))))                                                        VVVVAAAARRRRAAAARRRRGGGGSSSS((((3333FFFF))))
  71.  
  72.  
  73.  
  74.      _x_e_t_a_r_g initializes _l_e_n bytes of _i_a_r_g with the value of the _nth argument .
  75.  
  76.      _r_e_t_o_u_r returns values to the calling program by setting _n_a_r_g_s actual
  77.      arguments using _l_e_n_1, _l_e_n_2,..., _l_e_n_n bytes of the values stored in the
  78.      variables _v_a_l_1, _v_a_l_2,..., _v_a_l_n, respectively.
  79.  
  80.      In normal usage of variable argument subroutines, when the formal
  81.      argument list is specified using the maximum number of arguments the
  82.      subroutine can received, the argument addresses and return values are
  83.      passed in the standard f77 convention.  The only utility needed in this
  84.      case is _a_r_g_m_n_t to determine the number of actual arguments passed to the
  85.      variable argument subroutine.
  86.  
  87.      The other utilities are needed when there is no formal argument list in
  88.      the variable argument subroutine. _x_e_t_a_r_g is normally used to initializes
  89.      some local variables to the initial values of the actual arguments.
  90.      _r_e_t_o_u_r is then used to return the locally calculated values back to the
  91.      calling subroutine by setting the actual arguments to the values of the
  92.      local variables.
  93.  
  94.      Example:
  95.  
  96.      $varargs chsign
  97.           program tvararg
  98.           i = 1
  99.           j = -2
  100.           k = 3
  101.           call chsign( i, j, k, "fourth argument", "fifth" )
  102.           print *, i, j, k
  103.           end
  104.  
  105.           subroutine chsign()
  106.      C    This subroutine changes the sign of all integer arguments passed to it
  107.      C    and prints the value of all character arguments.  It assumes that
  108.      C    there are at most three integer arguments, followed by the character
  109.      C    arguments.  The way this subroutine is written it has to be compiled
  110.      C    with the -chararg1 option since it assumes that the lengths of the
  111.      C    character arguments can be obtained by using GETADR(NARGS+I) where
  112.      C    NARGS is the number of arguments returned by ARGMNT().
  113.           integer*4 val(3)
  114.           pointer (stradr, str)
  115.           character*(*) str
  116.  
  117.           call argmnt( nargs )
  118.           print *, "Number of arguments = ", nargs
  119.           j = min(3,nargs)
  120.           do 10 i=1,j
  121.               call xetarg( i, 4, val(i) )
  122.      10   val(i) = - val(i)
  123.      C    Get the address and the length of the character arguments
  124.              do 100 i=j+1, nargs
  125.                  call getadr( i, stradr )
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. VVVVAAAARRRRAAAARRRRGGGGSSSS((((3333FFFF))))                                                        VVVVAAAARRRRAAAARRRRGGGGSSSS((((3333FFFF))))
  137.  
  138.  
  139.  
  140.                  call getadr( nargs+i-j, lenstr )
  141.                  write (*,*) str(1:lenstr)
  142.      100     continue
  143.  
  144.           call retour(j,4,val(1),4,val(2),4,val(3))
  145.           end
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.